#pragma once
    
    #include <vector>
    #include <memory>
    #include <functional>
    #include <transfer/ITransfer.h>
    #include "cp/CP_ServiceId.h"
    
    namespace ecarx::transfer::apcp {
    
        class APCPConn:public ITransfer{
            class NetAPCP;
            NetAPCP* mImpl;
            public:
            explicit APCPConn();
            ~APCPConn();
            //打开链接
            bool open() override;
            //关闭链接
            bool close() override;
            //将数据写到网络上
            bool write(const Signal &) override;
            const std::optional<Signal> read(const int32_t signalId) const override;
            NetState getState() override;
            void onSignalChanged(SignalChangeCallback && callback) override;
            void registerStateHandler(NetStateCallback && callback) override;
        

        };
    
        struct ValidOperationArray {
            int len;
            uint16_t *oper_ids;
        };
    
        static uint16_t CPNormalOps[] = {0x1001,0x1002,0x1003,0x1004,0x1005,0x1006,0x1007,0x1008,0x1009,0x100a,
                                     0x100b,0x100c,0x100d,0x100e,0x100f,0x1010,0x1011,0x1012,0x1013,0x1014,
                                     0x1015,0x1016,0x1017,0x1018,0x1019,0x101a,0x101b,0x101c,0x101d,0x101e,
                                     0x101f,0x1020,0x1021,0x1022,0x1023,0x1024,0x1025,0x1026,0x1027,0x1028,
                                     0x1029,0x102a,0x102b,0x102c,0x102d,0x102e,0x102f,0x1030,0x1031,0x1032,
                                     0x1033,0x1034,0x1035,0x1036,0x1040,0x1042,0x1043,0x1044,
                                     0x2001,0x2002,0x2003,0x2004,0x2005,0x2006,0x2007,0x2008,0x2009,0x200a,
                                     0x200b,0x200c,0x200d,0x200e,0x200f,0x2010,0x2011,0x2012,0x2013,0x2014,
                                     0x2015,0x2016,0x2017,0x2018,0x2019,0x201a,0x201b,0x201c,0x201d,0x201e,
                                     0x201f,0x2020,0x2021,0x2022,0x2023,0x2024,0x2025,0x2026,0x2027,0x2028,
                                     0x2029,0x202a,0x202b,0x202c,0x202d,0x202e,0x202f,0x2030,0x2031,0x2032,
                                     0x2033,0x2034,0x2035,0x2038,0x2039,0x203a,0x203b,0x203c,0x203d,0x203e,
                                     0x203f,0x2040,0x2041,0x2042,0x2043,0x2044,0x2045,0x2046,0x2047,0x2048,
                                     0x2049,0x204a,0x204b,0x204c,0x204d,0x204e,0x204f,0x2050,0x2051,0x2052,
                                     0x2053,0x2054,0x2055,0x2056,0x2057,0x2058,0x2059};
        static uint16_t CPTimeSyncOps[] = {0x1001,0x1002,
                                       0x2001};
        static uint16_t CPAVASOps[] = {0x1001,0x1002,0x1003,0x1004,
                                   0x2001,0x2002};
        static uint16_t CPHostInfoOps[] = {0x1001,0x1005,0x1006,0x1007,0x1008,0x1009,
                                   0x2001,0x2003,0x2004,0x2005,0x2006,0x2007};
        static uint16_t CPPowerOps[] = {0x1001,0x1002,
                                   0x2001};
    
        ValidOperationArray getValidOperationArray(uint16_t serviceId) {
            switch (serviceId) {
                case CP_serviceID_Normal:
                    return ValidOperationArray{
                            .len = 145,
                            .oper_ids = CPNormalOps,
                    };
                case CP_serviceID_TimeSync:
                    return ValidOperationArray{
                            .len = 3,
                            .oper_ids = CPTimeSyncOps,
                    };
                case CP_serviceID_AVAS:
                    return ValidOperationArray{
                            .len = 6,
                            .oper_ids = CPAVASOps,
                    };
                case CP_serviceID_HostInfo:
                    return ValidOperationArray{
                            .len = 12,
                            .oper_ids = CPHostInfoOps,
                    };
                case CP_serviceID_Power:
                    return ValidOperationArray{
                            .len = 3,
                            .oper_ids = CPPowerOps,
                    };
                default:
                    return ValidOperationArray{};
            }
        }
    
        const uint16_t getReadyServiceIds[] = {
                CP_serviceID_Normal,
                CP_serviceID_TimeSync,
                CP_serviceID_AVAS,
                CP_serviceID_HostInfo,
                CP_serviceID_Power,
        };
    
    }
    